import bean.SomeBean;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.style.StyleUtil;
import mediainfo.MovieMetadataParser;
import mediainfo.domain.Audio;
import mediainfo.domain.General;
import mediainfo.domain.MovieMetadata;
import mediainfo.domain.Video;
import org.apache.poi.ss.usermodel.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

public class Application {
    public static void main(String[] args) throws IOException {
        File[] selectDirs;
        if (ArrayUtil.isNotEmpty(args)) {
            System.out.println("参数：" + Arrays.toString(args));
            selectDirs = Arrays.stream(args).map(File::new).toArray(File[]::new);
        } else {
            System.out.println("无参数");
            selectDirs = new File[]{
                    new File("d:\\")
                    , new File("e:\\")
                    , new File("f:\\")
                    , new File("g:\\")
                    , new File("h:\\")
                    , new File("i:\\")
                    , new File("k:\\")
                    , new File("j:\\")
                    , new File("l:\\")
//                , new File("/Users/wuganglin")
            };
        }

        if (ArrayUtil.isNotEmpty(selectDirs)) {
            List<File> dirList = Arrays.stream(selectDirs).filter(Objects::nonNull).collect(Collectors.toList());
            Map<String, Long> collect = dirList.stream().collect(Collectors.groupingBy(File::getAbsolutePath, Collectors.counting()));
            if (collect.values().stream().anyMatch(i -> i > 1)) {
                System.out.println("不要选择重复的目录!");
                return;
            }

            ExcelWriter writer = null;
            String path = FileUtil.getParent(
                    URLDecoder.decode(Application.class.getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8"), 1);
            String s = path + File.separator + "all.xlsx";
            MovieMetadataParser instance = MovieMetadataParser.getInstance();
            String cachePath = path + File.separator + "cache.json";
            System.out.println("路径：" + s + " " + cachePath);
            JSONObject json = new JSONObject();
            if (FileUtil.isFile(cachePath)) {
                String cache = FileUtil.readUtf8String(cachePath);
                if (StrUtil.isNotBlank(cache)) {
                    json = new JSONObject(cache);
                }
            }


            for (File selectDir : dirList) {
                if (null != selectDir && selectDir.exists() && selectDir.isDirectory()) {
                    System.out.println("正在处理文件：" + selectDir.getAbsolutePath());

                    String replace = FileNameUtil.cleanInvalid(selectDir.getAbsolutePath());
                    if (null == writer) {
                        writer = ExcelUtil.getBigWriter();
                    }
                    if (writer.getSheet().getSheetName().equals("sheet1")) {
                        writer.renameSheet(replace);
                    } else {
                        writer.setSheet(replace);
                    }
                    writer.setFreezePane(1);
                    CellStyle defaultCellStyle = StyleUtil.createDefaultCellStyle(writer.getWorkbook());
                    defaultCellStyle.setAlignment(HorizontalAlignment.LEFT);
                    CellStyle firstRowStyle = StyleUtil.createDefaultCellStyle(writer.getWorkbook());
                    firstRowStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
                    firstRowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                    Font font = writer.getWorkbook().createFont();
                    font.setFontName("黑体");
                    font.setFontHeightInPoints((short) 12);//设置字体大小
                    font.setBold(true);
                    firstRowStyle.setFont(font);

//                    CellStyle textStyle = StyleUtil.createDefaultCellStyle(writer.getWorkbook());
//                    textStyle.setIndention();
                    if (StrUtil.containsAny(selectDir.getAbsolutePath(), "smb://", "/Volumes/")) {
                        System.out.println("选择的目录错误，请选择本地目录!");
                        return;
//                        SmbFile smbFile = new SmbFile(selectDir.getAbsolutePath());
//                        if (smbFile.isDirectory()) {
//                            List<SmbFile> files = loopSmbFiles(smbFile);
//                            files.sort(Comparator.comparing(SmbFile::getName));
//                            if (CollUtil.isNotEmpty(files)) {
//                                writer.writeCellValue(0, 0, "文件名");
//                                writer.writeCellValue(1, 0, "路径");
//                                for (int i = 0; i < files.size(); i++) {
//                                    writer.writeCellValue(0, i + 1, files.get(i).getName());
//                                    String canonicalPath = files.get(i).getCanonicalPath();
//                                    String uncPath = files.get(i).getUncPath();
//                                    String dfsPath = files.get(i).getDfsPath();
//                                    writer.writeCellValue(1, i + 1, files.get(i).getUncPath());
//                                }
//                            }
//
//                        }
                    } else {
                        List<File> files = new ArrayList<>();
                        Files.walkFileTree(selectDir.toPath(), new SimpleFileVisitor<Path>() {
                            @Override
                            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {

                                if (FileNameUtil.isType(file.toFile().getName(), "mkv")
                                        && !file.toFile().isHidden() && !file.toFile().getAbsolutePath().contains("$RECYCLE.BIN")
                                        && !file.toAbsolutePath().toString().contains("NotScan")) {
                                    files.add(file.toFile());
                                    System.out.print(".");
                                    return FileVisitResult.CONTINUE;
                                }
                                return FileVisitResult.SKIP_SUBTREE;
                            }

                            //增加失败处理，直接过滤
                            @Override
                            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                                if (exc instanceof AccessDeniedException) {
                                    return FileVisitResult.SKIP_SUBTREE;
                                }
                                return super.visitFileFailed(file, exc);
                            }
                        });
                        System.out.println();

                        files.sort(Comparator.comparing(File::getName));
                        if (CollUtil.isNotEmpty(files)) {

                            AtomicInteger headColumnNumber = new AtomicInteger(0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "名称").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "年份").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "国家").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "评分").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "来源").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "文件名").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "时长").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "格式").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "大小").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "编码").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "码率").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "色深").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "分辨率").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "音效").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "声道").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);

                            writer.writeCellValue(headColumnNumber.get(), 0, "路径").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "视频流").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);
                            writer.writeCellValue(headColumnNumber.get(), 0, "音频流").setStyle(firstRowStyle, headColumnNumber.getAndIncrement(), 0);

                            AtomicReference<String> percent = new AtomicReference<>("");
                            JSONObject finalJson = json;
                            AtomicInteger num = new AtomicInteger(0);
                            List<Map<Integer, String>> list = files.parallelStream().map(file -> {
                                try {
                                    AtomicInteger columnNumber = new AtomicInteger(0);
                                    Map<Integer, String> map = new HashMap<>();

                                    String nfoFilePath = file.getParent() + File.separator + FileNameUtil.mainName(file.getName()) + ".nfo";
                                    File nfo = new File(nfoFilePath);
                                    if (nfo.exists()) {
                                        try {
                                            String infoStr = FileUtil.readUtf8String(nfo);
                                            String tvshowNfoStr = null;
                                            String tvshowNfoFilePath = file.getParentFile().getParent() + File.separator + "tvshow.nfo";
                                            File tvshowNfo = new File(tvshowNfoFilePath);

                                            if (tvshowNfo.exists()) {
                                                tvshowNfoStr = FileUtil.readUtf8String(tvshowNfo);
                                            }

                                            SomeBean someBean = getSomes(infoStr, tvshowNfoStr);
                                            map.put(columnNumber.getAndIncrement(), someBean.getName());
                                            map.put(columnNumber.getAndIncrement(), someBean.getYear());
                                            map.put(columnNumber.getAndIncrement(), someBean.getCountry());
                                            map.put(columnNumber.getAndIncrement(), someBean.getImdb());
                                            map.put(columnNumber.getAndIncrement(), someBean.getSource());
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            System.out.print("文件名：" + file.getAbsolutePath());
                                        }
                                    } else {
                                        columnNumber.set(5);
                                    }
                                    String md5 = MD5.create().digestHex(file.getAbsolutePath());
                                    MovieMetadata movieMedataData;
                                    JSONObject jsonObject = finalJson.getJSONObject(md5);
                                    if (jsonObject != null) {
                                        movieMedataData = jsonObject.toBean(MovieMetadata.class);
                                    } else {

                                        String mediainfoFilePath = file.getParent() + File.separator + FileNameUtil.mainName(file.getName()) + "-mediainfo.xml";
                                        File mediainfo = new File(mediainfoFilePath);
                                        if (mediainfo.exists()) {
                                            String mediainfoStr = FileUtil.readUtf8String(mediainfo);
                                            movieMedataData = xmlToMovieMetadata(mediainfoStr);
                                        } else {
                                            movieMedataData = instance.parseFile(file);
                                        }
                                        finalJson.set(md5, JSONUtil.parseObj(movieMedataData));
                                    }
                                    String format = movieMedataData.get(General.FORMAT);
                                    String fileSize = movieMedataData.get(General.FILESIZE_ASSTRING);
                                    String videoFormat = movieMedataData.get(Video.FORMAT);
                                    String duration = String.valueOf(NumberUtil.toBigDecimal(movieMedataData.get(Video.DURATION)).divide(new BigDecimal(60), RoundingMode.UP).intValue());
                                    String bitdepth = movieMedataData.get(Video.BITDEPTH_STRING);
                                    String resolution = movieMedataData.get(Video.WIDTH) + "x" + movieMedataData.get(Video.HEIGHT);
                                    String bitRate = movieMedataData.get(Video.BITRATE_STRING);
                                    String formatCommercialIfany = movieMedataData.get(Audio.FORMAT_COMMERCIAL_IFANY);
                                    String channel = movieMedataData.get(Audio.CHANNEL);
                                    String videoList = JSONUtil.toJsonPrettyStr(movieMedataData.getVideoKeysList());
                                    String audioList = JSONUtil.toJsonPrettyStr(movieMedataData.getAudioKeysList());
                                    map.put(columnNumber.getAndIncrement(), file.getName());
                                    map.put(columnNumber.getAndIncrement(), duration);
                                    map.put(columnNumber.getAndIncrement(), format);
                                    map.put(columnNumber.getAndIncrement(), fileSize);
                                    map.put(columnNumber.getAndIncrement(), videoFormat);
                                    map.put(columnNumber.getAndIncrement(), bitRate);
                                    map.put(columnNumber.getAndIncrement(), bitdepth);
                                    map.put(columnNumber.getAndIncrement(), resolution);
                                    map.put(columnNumber.getAndIncrement(), formatCommercialIfany);
                                    map.put(columnNumber.getAndIncrement(), channel);
                                    map.put(columnNumber.getAndIncrement(), file.getAbsolutePath());
                                    map.put(columnNumber.getAndIncrement(), videoList);
                                    map.put(columnNumber.getAndIncrement(), audioList);

                                    int i = num.getAndIncrement();
                                    String nowPercent = StrUtil.fillBefore(NumberUtil.formatPercent((double) (i + 1) / (double) files.size(), 0), ' ', 3);
                                    if (!nowPercent.equals(percent.get())) {
                                        percent.set(nowPercent);
                                        System.out.println("(" + (i + 1) + "/" + files.size() + ") " + nowPercent);

                                    }

                                    return map;
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    System.out.print("文件名：" + file.getAbsolutePath());
                                    return null;
                                }
                            }).filter(Objects::nonNull).sorted(Comparator.comparing(map -> map.get(5), String.CASE_INSENSITIVE_ORDER)).collect(Collectors.toList());
                            for (int i = 0; i < list.size(); i++) {
                                Map<Integer, String> map = list.get(i);
                                Set<Map.Entry<Integer, String>> entries = map.entrySet();
                                for (Map.Entry<Integer, String> entry : entries) {
                                    writer.writeCellValue(entry.getKey(), i + 1, entry.getValue());
                                    if (entry.getKey() == 0 || entry.getKey() == 5 || entry.getKey() == 15) {
                                        writer.setStyle(defaultCellStyle, entry.getKey(), i + 1);
                                    }
                                }
                            }

                            headColumnNumber.set(0);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 50);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 6);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 10);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 6);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 13);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 80);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 6);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 10);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 10);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 8);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 11);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 8);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 11);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 30);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 6);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 200);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 50);
                            writer.setColumnWidth(headColumnNumber.getAndIncrement(), 50);

                            System.out.println();

                        }
                    }
                }
            }
            if (writer != null) {
                System.out.println("写入json缓存:" + cachePath);
                FileUtil.writeUtf8String(json.toStringPretty(), cachePath);
                System.out.println("写入xlsx:" + s);
                writer.flush(new File(s));
            }

        }
    }

    public static MovieMetadata xmlToMovieMetadata(String xml) {
        MovieMetadata movieMetadata = null;
        if (StrUtil.isNotBlank(xml)) {
            movieMetadata = new MovieMetadata();
            Document document = XmlUtil.parseXml(xml);
            Node mediaInfo = document.getElementsByTagName("MediaInfo").item(0);
            for (int i = 0; i < mediaInfo.getChildNodes().getLength(); i++) {
                Node node = mediaInfo.getChildNodes().item(i);
                if (node.getNodeName().equals("media")) {
                    for (int j = 0; j < node.getChildNodes().getLength(); j++) {
                        Node track = node.getChildNodes().item(j);
                        if (track.getNodeName().equals("track")) {
                            String type = track.getAttributes().getNamedItem("type").getTextContent();
                            Node typeorderNode = track.getAttributes().getNamedItem("typeorder");
                            String typeorder = null != typeorderNode ? typeorderNode.getTextContent() : null;
                            if (StrUtil.isNotBlank(type) && (StrUtil.isBlank(typeorder) || StrUtil.equals(typeorder, "1"))) {
                                for (int k = 0; k < track.getChildNodes().getLength(); k++) {

                                    Node n = track.getChildNodes().item(k);
                                    if (StrUtil.equals(type, "General")) {
                                        if (n.getNodeName().equals(General.FORMAT.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setGeneralKey(General.FORMAT, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(General.FILESIZE_ASSTRING.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setGeneralKey(General.FILESIZE_ASSTRING, n.getTextContent());
                                        }
                                    } else if (StrUtil.equals(type, "Video")) {
                                        if (n.getNodeName().equals(Video.FORMAT.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.FORMAT, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Video.DURATION.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.DURATION, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Video.BITDEPTH_STRING.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.BITDEPTH_STRING, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Video.HEIGHT.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.HEIGHT, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Video.WIDTH.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.WIDTH, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Video.BITRATE_STRING.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setVideoKey(Video.BITRATE_STRING, n.getTextContent());
                                        }
                                    } else if (StrUtil.equals(type, "Audio")) {
                                        if (n.getNodeName().equals(Audio.FORMAT_COMMERCIAL_IFANY.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setAudioKey(Audio.FORMAT_COMMERCIAL_IFANY, n.getTextContent());
                                        }
                                        if (n.getNodeName().equals(Audio.CHANNEL.getKey().replaceAll("/", "_"))) {
                                            movieMetadata.setAudioKey(Audio.CHANNEL, n.getTextContent());
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
        return movieMetadata;
    }

    private static SomeBean getSomes(String infoStr, String tvshowNfoStr) {
        return getSomes(infoStr, tvshowNfoStr, new SomeBean());
    }

    private static SomeBean getSomes(String infoStr, String tvshowNfoStr, SomeBean someBean) {
        if (StrUtil.count(infoStr, "</episodedetails>") > 1) {
            String[] split = infoStr.split("</episodedetails>");
            for (String s : split) {
                if (StrUtil.isNotBlank(s)) {
                    getSomes(s + "</episodedetails>", tvshowNfoStr, someBean);
                }
            }
        } else {
            Document document = XmlUtil.parseXml(infoStr);
            Node movie = document.getElementsByTagName("movie").item(0);
            if (null == movie) {
                movie = document.getElementsByTagName("episodedetails").item(0);
            }
            if (null != movie) {
                String title = "";
                String year = "";
                List<String> country = new ArrayList<>();
                String imdb = "";
                String premiered = "";
                String source = "";
                String showtitle = "";
                String season = "";
                String episode = "";
                if (StrUtil.isNotBlank(tvshowNfoStr)) {
                    Document tvshowDocument = XmlUtil.parseXml(tvshowNfoStr);
                    Node tvshow = tvshowDocument.getElementsByTagName("tvshow").item(0);
                    for (int j = 0; j < tvshow.getChildNodes().getLength(); j++) {
                        Node node = tvshow.getChildNodes().item(j);
                        if (node.getNodeName().equals("showtitle")) {
                            showtitle = node.getTextContent();
                        }
                        if (node.getNodeName().equals("country")) {
                            country.add(node.getTextContent());
                        }
                    }
                }
                for (int j = 0; j < movie.getChildNodes().getLength(); j++) {
                    Node node = movie.getChildNodes().item(j);
                    if (node.getNodeName().equals("title")) {
                        title = node.getTextContent();
                    }
                    if (node.getNodeName().equals("year")) {
                        year = node.getTextContent();
                    }
                    if (node.getNodeName().equals("premiered")) {
                        premiered = node.getTextContent();
                    }
                    if (node.getNodeName().equals("country")) {
                        country.add(node.getTextContent());
                    }
                    if (node.getNodeName().equals("ratings")) {
                        for (int k = 0; k < node.getChildNodes().getLength(); k++) {
                            Node rating = node.getChildNodes().item(k);
                            if (rating.getNodeName().equals("rating")) {
                                String ratingName = rating.getAttributes().getNamedItem("name").getTextContent();
                                if (ratingName.equals("imdb")) {
                                    for (int t = 0; t < rating.getChildNodes().getLength(); t++) {
                                        Node imdbNode = rating.getChildNodes().item(t);
                                        if (imdbNode.getNodeName().equals("value")) {
                                            imdb = imdbNode.getTextContent();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (node.getNodeName().equals("source")) {
                        source = node.getTextContent();
                    }
                    if (StrUtil.isBlank(showtitle) && node.getNodeName().equals("showtitle")) {
                        showtitle = node.getTextContent();
                    }
                    if (node.getNodeName().equals("season")) {
                        season = StrUtil.fillBefore(node.getTextContent(), '0', 2);
                    }
                    if (node.getNodeName().equals("episode")) {
                        episode = StrUtil.fillBefore(node.getTextContent(), '0', 2);
                    }
                }
                if (StrUtil.isAllNotEmpty(showtitle, season, episode)) {
                    someBean.setShowtitle(showtitle);
                    someBean.setSeason(season);
                    if (StrUtil.isNotEmpty(someBean.getEpisode())) {
                        episode = someBean.getEpisode() + episode;
                    }
                    someBean.setEpisode(episode);
                    if (StrUtil.isNotEmpty(someBean.getTitle())) {
                        title = someBean.getTitle() + " | " + title;
                    }
                    someBean.setTitle(title);
                    someBean.setName(showtitle + "." + "S" + season + "E" + episode + "." + title);
                } else {
                    someBean.setTitle(title);
                    someBean.setName(title);
                }
                if (StrUtil.isNotEmpty(year)) {
                    someBean.setYear(year);
                } else if (StrUtil.isNotEmpty(premiered)) {
                    someBean.setPremiered(premiered.substring(0, 4));
                    someBean.setYear(someBean.getPremiered());
                }
                someBean.setSource(source);
                someBean.setCountry(StrUtil.join(StrUtil.COMMA, country));
                someBean.setImdb(imdb);
            }
        }
        return someBean;
    }


}
